{extend name="public/base" /} {block name="css"}
{extend name="public/base" /} {block name="css"}
<link rel="stylesheet" href="__INDEX__/css/add_clothes.css"> 
<style>
table{ width: 100%;border-collapse: collapse;}
#chanpin>tr>td{ text-align: center;border:1px solid #ccc; height: 30px;line-height: 30px;}
#chanpin tr th{ text-align: center;border:1px solid #ccc;height: 30px;line-height: 30px; }
table>tr>td{ text-align: center;border:1px solid #ccc; height: 30px;line-height: 30px;}
table tr th{ text-align: center;border:1px solid #ccc;height: 30px;line-height: 30px; }
table tr th input{ width: 100% ;border: 0};
table tr td input{ width: 100% ;border: 0};
</style>
{/block}
{block name="container"}

<div class="panel-body panel-body-nopadding" style="padding-bottom:50px;">
    <div class="inforMain">
        <div class="title">店铺库存编码录入</div>
        <span>*请用扫码枪扫成衣对应的条形码*</span>
        <input type="text" id="maBoxs">
    </div>
    <div id="info" style="display: none">
        <form class="form-horizontal form-bordered" id="submitForm" action="/index/shop/writeKucun" method="post" style="margin:38px auto !important;" > 
            <div class="form-group" >
                <table id="chanpin">
                    <tr>
                        <th>序号</th>
                        <th>商品名称</th>
                        <th>面料编号</th>
                        <th>条码编号</th>
                        <th>面料属性</th>
                        <th>性别</th>
                        <th>季节</th>
                        <th>品类</th>
                        <th>号型</th>
                        <th>颜色</th>
                        <th>价格</th>
                        <th>数量</th>
                    </tr>
                </table>
                 <table>
                    <tr>
                        <th style="width: 45%;text-align: center;">合计</th>
                        <th ><input id="all" style="text-align: center;" name="total"   value="" /></th>
                    </tr>
                </table>
            </div>
            <div class="panel-footer">
             <div class="row">
              <div class="col-sm-6 col-sm-offset-3">
                <button type="submit" class="btn btn-primary">提交</button>
                <button type="button" class="btn btn-default" onclick="javascript:history.back(-1);">返回</button>
            </div>
        </div>
    </form>
</div>
</div>
{/block} 
{block name="js"}
<script>
        var  i = 0;
        var sum = 0;
        $(function(){
        document.getElementById('maBoxs').focus();

        $('#maBoxs').bind('keydown', function(event) {
            if (event.keyCode == "13") {
                //回车执行查询
                var aa = $('#maBoxs').val();
                //alert(aa);
                $.post('{:url("index/Administration/getInfoForAjax")}', {order: aa}, function(data) {
                    if(data.sus == 1){
                        i++;
                        
                        for(var j=0; j< i;  j++ ){
                            if($('#code_'+j).val() == data['code']){
                                var num = $("#num_"+j).val();
                                num++;
                                document.getElementById('maBoxs').value = '';
                                document.getElementById('num_'+j).value = num;
                                document.getElementById('all').value = i;
                                return false;
                            }
                        }
                        var html = `
                        <tr>
                            <td>`+i+`</td>
                            <td>`+data['name']+`</td>
                            <td>`+data['ml_num']+`</td>
                            <td>`+data['code']+`<input type="hidden" name="code[]" id="code_`+i+`" value ="`+data['code']+`"/></td>
                            <td>`+data['ml_style']+`</td>
                            <td>`+data['sex']+`</td>
                            <td>`+data['season']+`</td>
                            <td>`+data['category']+`</td>
                            <td>`+data['size']+`</td>
                            <td>`+data['color']+`</td>
                            <td>`+data['price']+`<input  type="hidden" id="name_`+i+`"  value="`+data['price']+`"/></td>
                            <td><input type="text" style="width:100%;border:0px;text-align:center;" name="num[]" id="num_`+i+`" value="1"/></td>
                        </tr>`;
                       $('#chuku').focus(); 
                       $("#chanpin").append(html);
                       getAllNum(i);
                       document.getElementById('maBoxs').value = '';   
                       document.getElementById('all').value = i;         
                       $('#info').css('display', 'block');

                    }else{
                       swal({
                            title: "没有此商品",      
                            text: "",
                            type: "error"
                        }); 
                   }
                });
                
            }
        });
    });



        function getAllNum(id)
    {
       for(var j = 1 ; j<= id; j++)
       {
          sum = parseInt(sum) +parseInt($('#num_'+j).val());
      }
      document.getElementById('all').value = sum;
      sum = 0;
    }
</script>

 {/block}